const router = require('koa-router')()
const { register,login } = require('../mysql/index.js')

router.post('/register',async (ctx,next) =>{
  try{
    console.log(ctx.request.body);
    let res = await login({account:ctx.request.body.number})
    console.log(res);
    if(res.length>0){
      ctx.body={
        code:'1',
        msg:'该手机号已注册',
        state:false
      }
    }
    else{
      let result = await register({
        number:ctx.request.body.number,
        name:ctx.request.body.name,
        password:ctx.request.body.password,
      })
      console.log(result);
      ctx.body={
        code:'1',
        msg:'注册成功',
        state:true
      }
    }
  }catch(e){
    ctx.body={
      msg:e
    }
    console.log(e,'aaaaaaaaa');
  }
})

module.exports = router
